#ifndef SERVER_H
#define SERVER_H

#include "session.h"

#include <cstdint>
#include <mutex>
#include <memory>
#include <map>
#include <string>

#include <boost/asio.hpp>

class Server
{
public:
    using TCP = boost::asio::ip::tcp;
    using IOContext = boost::asio::io_context;

    Server(boost::asio::io_context& io_context, uint16_t port);
    void DeleteSession(const std::string& uuid);
    void AddSession(const std::string& uuid, std::shared_ptr<Session> session);

private:
    void _StartAccept();
    void _HeadleAccetp(std::shared_ptr<Session>, const boost::system::error_code& error);

private:
    IOContext m_context;
    TCP::acceptor m_acceptor;
    uint16_t m_port;
    std::map<std::string, std::shared_ptr<Session>> m_sessions;
    std::mutex m_session_mtx;
};  

#endif //SERVER_H
